{% extends 'AdminBundle::layout.html.twig' %}

{% block title %}申报看板{% endblock %}


   {% block css %}{% endblock %}


    {% block top %}
        {{ parent() }}
    {% endblock %}


    {% block left_body_top %}
        {{ parent() }}
    {% endblock %}


    {% block left_body %}
        {{ parent() }}
    {% endblock %}

    {% block right_body %}
    <div class="page-header">
        <div class="page-right-top">
            <div class="right-top">
                <span class="right-title">申报看板</span>
            </div>
        </div>
        <div class="main-content">
            <div class="main-top">
                <div class="index-list declare-m1">
                    <div class="index-total">项目总数</div>
                    <div class="index-totalNum">
                        <span class="all-count"></span>件
                    </div>
                </div>
                <div class="index-list declare-m2">
                    <div class="index-total" style="padding-top: 13px;">今日已结束项目数</div>
                    <div class="index-totalNum">
                        <span>0</span>件
                    </div>
                </div>
                <div class="index-list declare-m3">
                    <div class="index-total">今日未结束项目数</div>
                    <div class="index-totalNum">
                        <span>0</span>件
                    </div>
                </div>
                <div class="index-list declare-m4">
                    <div class="index-total">今日新增项目数</div>
                    <div class="index-totalNum">
                        <span class="new-count"></span>件
                    </div>
                </div>
            </div>

            <div class="mes-content">
                <div class="main-mes-top">
                    <div class="fl">
                        <a class="release-btn fl" style="width:140px;"  href="{{ path('project_edit',{id:0}) }}">
                            <div class="re-width" style="width: 95px;">
                                <span class="me-icon fl"></span>
                                <span class="re-text fl">添加新项目</span>
                            </div>
                        </a>
                    </div>

                    <div class="fr">
                        <div class="mes-input fl">
                            <input type="text" class="keyword-input" name="keyword" placeholder="请输入查询关键词">
                        </div>

                        <button class="mes-query-btn fl">查询</button>
                    </div>
                    <div class="clearfix"></div>
                </div>

                <div class="main-mes-content">
                    <div class="al-released fl">今日项目列表 - {{ date }}</div>

                    <table class="table" style="table-layout:fixed;">
                        <thead>
                        <tr style="background-color: #f3f9fd;">
                            <th style="width: 35%;" class="center-th">项目名称</th>
                            <th class="center-th">项目类型</th>
                            <th class="center-th">项目进度</th>
                            <th class="center-th">详情</th>
                            <th class="center-th">操作</th>
                        </tr>
                        </thead>
                        <tbody>





                        </tbody>
                    </table>

                    <div class="page-box">
                        <ul class="pagination">

                        </ul>
                    </div>
                </div>
            </div>
        </div>
    </div>
    {% endblock %}


{% block box %}
{% endblock %}

{% block javascript %}
    {{ parent() }}
<script type="text/javascript">

        SidebarHighlighting('5');

        // 点击查询
        var search_keyword = "";
        $('.mes-query-btn').on('click', function() {
            search_keyword = $("input[name='keyword']").val();

//            if ($.trim(search_keyword) == '') {
//                popStatus(2, '请输入关键字', 1,'', true);
//                return;
//            }

            page_times = 0;
            addSearchAction(1);


        });

        // 删除
        $('body').on('click', '.tab-disable', function() {

            var id = $(this).data("id");

            if(confirm('您确定要删除吗？')) {

                $.getJSON("{{ path('api_admin_delete_project') }}",{id:id},function(data){
                    console.log(data);
                    if(data.errorCode == 0){
                        popStatus(1, '删除成功！', 1,'', true);
                        location.reload();
                    }
                })
            }
        });


        //获取项目列表
        var page_times = 0;
        function getList(page,search_keyword){
            page_times++;
            var param = {page:page,search_keyword:search_keyword};

            $.getJSON("{{ path('api_admin_project_list') }}",param,function(data){
                $("table tbody").empty(); //3
                console.log(data);

                var list_all_count = data.data.search_all_count;
                var allpage = data.data.all_page;

                // 分页样式
                if(page_times == 1 && allpage > 0){
                    pageAction(list_all_count,allpage);
                }

                if(allpage == 0){
                    $(".pagination").empty();
                }

                // 总数
                $(".all-count").text(data.data.allcount);
                //今日新增
                $(".new-count").text(data.data.newcount);

                var item = data.data.data;

                for(var i in item){
                    // 判断项目进度数据
                    var curr_progress = item[i].curr_progress_info;
                    var progress_key = "";
                    for(var j in curr_progress){
                        if(j != 0){
                            progress_key += ",";
                        }
                        progress_key += curr_progress[j];

                    }

                    if(progress_key == ""){
                        progress_key = "无";
                    }



                    var info_url = "{{ path('project_detail',{id:"7865459438475"}) }}".replace("7865459438475",item[i].id);

                    var edit_url = "{{ path('project_edit',{id:"65767878879"}) }}".replace("65767878879",item[i].id);
                    var html = '';

                    html += '<tr>';
                    html += '<td class="center-th a-line">'+ item[i].name +'</td>';
                    html += '<td class="center-th">'+ item[i].type +'</td>';
                    html += '<td class="center-th">'+ progress_key +'</td>';
                    html += '<td class="center-th">';
                    html += '<a href="'+ info_url +'">查看详情</a>';
                    html += '</td>';
                    html += '<td class="center-th">';
                    html += '<a class="table-opera tab-edit" href="'+ edit_url +'">编辑</a>';
                    html += '<span class="table-opera tab-disable" data-id="'+ item[i].id +'">| 删除</span>';
                    html += '</td>';
                    html += '</tr>';

                    $("table tbody").append(html);

                }
            })
        }

        addSearchAction(1);  //4

        //5
        function addSearchAction(page){
            getList(page,search_keyword);
        }

</script>
{% endblock %}